import request from '@/utils/request'
import { randomInt } from '@/utils/random'
const avatars = [
  'http://ylz.gswanzhong.com/Uploads/public/20200513/5ebbb8bc351f5.png',
  'http://ylz.gswanzhong.com/Uploads/public/20200513/5ebbb8d1af693.png',
  'http://ylz.gswanzhong.com/Uploads/public/20200513/5ebbb8da6950c.png',
  'http://ylz.gswanzhong.com/Uploads/public/20200513/5ebbb8e236e78.png',
  'http://ylz.gswanzhong.com/Uploads/public/20200513/5ebbb8eed2502.png',
]
export const fetchList = params => {
  return request({
    url: 'Tourarticle/lists',
    method: 'get',
    params,
  })
}

export const fetchData = (id, userId) => {
  const params = {
    tourarticleId: id,
  }
  if (typeof userId !== 'undefined') {
    params.userId = userId
  }
  return request({
    url: 'tourarticle/show',
    method: 'get',
    params,
  })
}
export const favToggle = (id, token) => {
  return request({
    url: '/favorite/toggle',
    method: 'get',
    params: {
      type: 'tour_article',
      id,
      token,
    },
  })
}
export const fav = (id, token) => {
  return request({
    url: '/favorite/add',
    method: 'get',
    params: {
      type: 'tour_article',
      id,
      token,
    },
  })
}
export const thumb = (id, userId) => {
  console.log('点赞', id, userId)
  return request({
    url: 'tourarticle/setHits',
    method: 'get',
    params: {
      tourarticleId: id,
      userId: userId,
    },
  })
}
export const randAvatar = id => {
  if (avatars.indexOf(id) > -1) return avatars[id]
  else {
    return avatars[randomInt(0, avatars.length - 1)]
  }
}
